package cn.edu.zafu.bigdata.lekang;

// 定义父类Vehicle
public class Vehicle {
    // 父类中的move()方法
    public void move() {
        System.out.println("Vehicle is moving");
    }
}

// 定义子类Car，继承Vehicle
class Car extends Vehicle {
    // 重写move()方法
    @Override
    public void move() {
        System.out.println("Car is moving");
    }
}

// 定义子类Bicycle，继承Vehicle
class Bicycle extends Vehicle {
    // 重写move()方法
    @Override
    public void move() {
        System.out.println("Bicycle is riding");
    }
}

// 测试类
class VehicleTest {
    public static void main(String[] args) {
        // 创建Vehicle数组，存储Car和Bicycle对象
        Vehicle[] vehicles = new Vehicle[2];
        vehicles[0] = new Car();
        vehicles[1] = new Bicycle();

        // 调用move()方法，展示多态性
        for (Vehicle vehicle : vehicles) {
            vehicle.move();
        }
    }
}